//
//  TimeIntervalExtensions.swift
//  clreader
//
//  Created by colin on 2019/4/2.
//  Copyright © 2019 colin. All rights reserved.
//

extension TimeInterval {
    /// 把秒数转换成时分秒（00:00:00）格式
    var hms:String {
        
        if self.isNaN || self.isInfinite {
            return "00:00"
        }
        
        let time = Int(self)
        
        let hours = time / 3600
        let hoursText = hours > 9 ? "\(hours)" : "0\(hours)"
        
        let minutes = time % 3600 / 60
        let minutesText = minutes > 9 ? "\(minutes)" : "0\(minutes)"
        
        let seconds = time % 3600 % 60
        let secondsText = seconds > 9 ? "\(seconds)" : "0\(seconds)"
        return hoursText == "00" ? "\(minutesText):\(secondsText)" : "\(hoursText):\(minutesText):\(secondsText)"
    }
}
